<template>
  <div>
    <!-- 面包屑头部导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片区域 -->
    <el-card class="box-card">
      <!-- 搜索框 -->
      <el-input style="width:30%" clearable placeholder="请输入内容">
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>

      <!-- 表格区域 -->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款">
          <template slot-scope="scope">
            <!-- {{scope.row.pay_status}} -->
            <el-tag v-if="scope.row.pay_status=1" type="danger">未付款</el-tag>
            <el-tag v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="发货时间">
          <template slot-scope="scope">{{scope.row.create_time | dataFormat}}</template>
        </el-table-column>
        <el-table-column label="操作">
          <el-button @click="showEditOrderDialog" type="primary" icon="el-icon-edit" circle></el-button>
          <el-button @click="showProgressDialog" type="success" icon="el-icon-location-outline" circle></el-button>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryData.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryData.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      ></el-pagination>
    </el-card>

    <!-- 编辑订单对话框 -->
    <el-dialog title="编辑订单" :visible.sync="editOrderDialogVisible" width="50%">
      <div>
        <el-cascader

          v-model="cascaderArr"
          :options="cityData"
          :props="props"
          @change="orderHandleChange"
        ></el-cascader>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editOrderDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editOrderDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 查看物流对话框 -->
    <el-dialog title="查看物流" :visible.sync="progressDialogVisible" width="50%">
      <el-timeline :reverse="true">
        <el-timeline-item
          v-for="(activity, index) in progressList"
          :key="index"
          :timestamp="activity.time"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from "../citydata.js";
export default {
  data() {
    return {
      queryData: {
        query: "",
        pagenum: 1,
        pagesize: 5
      },
      total: 0,
      orderList: [],
      editOrderDialogVisible: false,
      cascaderArr: [1,3,6],
      cityData,
      props: {
        expandTrigger: "hover",
        label: "label",
        value: "value"
      },
      progressDialogVisible: false,
      progressList: []
    };
  },

  methods: {
    //   获取表格数据
    async getOrders() {
      var res = await this.axios.get("orders", { params: this.queryData });
      if (res.meta.status == 200) {
        this.total = res.data.total;
        this.orderList = res.data.goods;
      }
      console.log(this.total);
      console.log(this.orderList);
    },

    // 每页多少条发生变化时触发
    handleSizeChange(val) {
      console.log(val);
      this.queryData.pagesize = val;
      this.getOrders();
    },
    // 页码发生变化时触发
    handleCurrentChange(val) {
      console.log(val);
      this.queryData.pagenum = val;
      this.getOrders();
    },

    // 展示编辑对话框
    showEditOrderDialog() {
      this.editOrderDialogVisible = true;
    },

    // 展示物流信息对话框
    async showProgressDialog() {
      this.progressDialogVisible = true;
      var res = await this.axios.get(`/kuaidi/106975712662`);
      if (res.meta.status == 200) {
        this.progressList = res.data;
      }
    },

    orderHandleChange() {}
  },

  created() {
    this.getOrders();
  }
};
</script>

<style lang='less' scoped>
</style>
